istio sidecar 注入規則

前言

因為drone 的 kubernetes Runner的關係,
導致我有一個ns要預設取消istio inject,
但某些特定的pod要注入就失敗了。

正文

先來看一張官方做的表(1),
其實就很好解釋為什麼不會注入了。

namespaceSelector match default policy Pod override annotation sidecar.istio.io/inject Sidecar injected?
yes enabled true (default) yes
yes enabled false no
yes disabled true yes
yes disabled false (default) no
no enabled true (default) no
no enabled false no
no disabled true no
no disabled false (default) no

各欄位解釋,

kubectl -n istio-system get configmap istio-sidecar-injector -o jsonpath='{.data.config}' | grep policy:

結論,
namespace只要是 disabled的,通通不會inject sidecar

指令篇

namespace

### 查看ns的label
kc get namespace --show-labels

### 新增修改 istio-injection
kubectl label namespace <my-namespace> istio-injection=enabled --overwrite

單獨指定deploy掛載sidecar

  apiVersion: apps/v1
  kind: Deployment
  metadata:
	name: grafana
	namespace: istio-system
  spec:
	replicas: 1
	selector:
	  matchLabels:
		app: websocketclient
	template:
	  metadata:
		creationTimestamp: null
		labels:
		  app: websocketclient
		  sidecar.istio.io/inject: 'true'

ref.
1. Automatic Sidecar Injection
2. Sidecar 自動注入問題
3. 關於Istio Automatic Sidecar Injection那檔事